package com.aspose.cells.a.d;

import com.aspose.cells.Color;

public class zdd extends zee {
   private com.aspose.cells.b.a.b.za d;
   private int e;
   private boolean f = false;
   private boolean g = false;

   private zdd() {
   }

   public zdd(com.aspose.cells.b.a.b.za var1, boolean var2) throws Exception {
      this.d = var1;
      this.g = var2;
      this.o();
      this.p();
   }

   private void o() {
      com.aspose.cells.b.a.b.za var1 = null;
      if (this.d.c() != 2498570 && this.d.c() != 139273) {
         var1 = zbn.a(this.d.i(), this.d.h());
         com.aspose.cells.b.a.b.zi var2 = com.aspose.cells.b.a.b.zi.a((com.aspose.cells.b.a.b.zj)var1);
         var2.a(this.d, 0, 0);
         this.d = var1;
      }

      this.e = this.d.c();
   }

   private void p() throws Exception {
      if (!this.i()) {
         this.q();
      } else {
         this.r();
      }

   }

   private void q() throws Exception {
      int var1 = this.d.i() * this.d.h() * 3;
      this.a = new byte[var1];
      int var2 = this.d.i() * this.d.h();
      this.b = new byte[var2];
      this.c = new Color[0];
      byte[] var3 = new byte[0];
      byte var4 = 0;
      byte[][] var5 = new byte[][]{var3};
      int[] var6 = new int[]{var4};
      zx.a(this.d, var5, var6);
      var3 = var5[0];
      int var18 = var6[0];
      int var10000 = var18 * this.d.h();
      int var8 = var18 < 0 ? this.a.length - this.d.i() * 3 : 0;
      int var9 = var18 < 0 ? this.b.length - this.d.i() * 1 : 0;
      int var10 = 0;
      this.f = true;

      for(int var11 = 0; var11 < this.d.h(); ++var11) {
         for(int var12 = 0; var12 < this.d.i(); ++var12) {
            this.a[var8 + 2] = var3[var10++];
            this.a[var8 + 1] = var3[var10++];
            this.a[var8 + 0] = var3[var10++];
            byte var13 = var3[var10++];
            this.b[var9++] = var13;
            if ((var13 & 255) < 255 && this.g) {
               double var14 = (double)var13 / 255.0D;
               double var16 = 1.0D - var14;
               this.a[var8 + 2] = (byte)((int)Math.round((double)(this.a[var8 + 2] & 255) * var14 + 255.0D * var16));
               this.a[var8 + 1] = (byte)((int)Math.round((double)(this.a[var8 + 1] & 255) * var14 + 255.0D * var16));
               this.a[var8 + 0] = (byte)((int)Math.round((double)(this.a[var8 + 0] & 255) * var14 + 255.0D * var16));
               this.f = false;
            }

            var8 += 3;
         }
      }

   }

   private void r() throws Exception {
      int var1 = (int)Math.ceil((double)((float)this.d.i() * (float)this.d() / 8.0F));
      int var2 = var1 * this.d.h();
      this.a = new byte[var2];
      int var3 = this.h() ? this.d.i() * this.d.h() * 1 : 0;
      this.b = new byte[var3];
      this.c = this.d.l().a();
      int var4 = 0;
      int var5 = 0;
      Object var6 = null;
      byte var7 = 0;
      byte[][] var8 = new byte[][]{(byte[])var6};
      int[] var9 = new int[]{var7};
      zx.a(this.d, var8, var9);
      byte[] var19 = var8[0];
      int var20 = var9[0];
      int var10000 = var20 * this.d.h();
      int var11 = var20 - var1;
      int var12;
      int var13;
      if (!this.h()) {
         for(var12 = 0; var12 < this.d.h(); ++var12) {
            for(var13 = 0; var13 < var1; ++var13) {
               this.a[var4++] = var19[var5++];
            }

            var5 += var11;
         }
      } else {
         var12 = 0;
         var13 = (1 << this.d()) - 1;

         for(int var14 = 0; var14 < this.d.h(); ++var14) {
            for(int var15 = 0; var15 < var1; ++var15) {
               this.a[var4] = var19[var5++];

               for(int var16 = 8 - this.d(); var16 > 0; var16 -= this.d()) {
                  int var17 = (this.a[var4] & 255) >> var16 & var13;
                  Color var18 = this.c[var17];
                  this.b[var12++] = var18.getA();
                  if ((var18.getA() & 255) < 255) {
                     this.f = true;
                  }
               }

               ++var4;
            }

            var5 += var11;
         }
      }

   }

   public com.aspose.cells.b.a.b.zj a() {
      return this.d;
   }

   public int b() {
      return this.d.i();
   }

   public int c() {
      return this.d.h();
   }

   public int d() throws Exception {
      switch(this.e) {
      case 137224:
      case 139273:
      case 198659:
      case 925707:
      case 2498570:
         return 8;
      case 196865:
         return 1;
      case 197634:
         return 4;
      case 1060876:
      case 1851406:
      case 3424269:
         return 16;
      default:
         throw new Exception("Unexpected pixel format.");
      }
   }

   public zdg e() {
      return this.i() ? zdg.c() : zdg.b();
   }

   public boolean f() {
      return this.f;
   }

   public boolean g() {
      return this.j() < 4096 && !this.f;
   }

   public boolean h() {
      return com.aspose.cells.b.a.b.zj.b(this.e) || this.i() && (this.d.l().b() & 1) == 1;
   }

   public boolean i() {
      return (this.e & 65536) == 65536;
   }

   public int j() {
      return this.d.i() * this.d.h() * com.aspose.cells.b.a.b.zj.a(this.e) / 8;
   }
}
